# -*- coding: utf-8 -*-
# @Time:2021/07/26 23:18
# @Author:Cindy


from flask import Flask, request, Request, session, make_response

app = Flask(__name__)
request: Request
app.secret_key = 'randomkey'


@app.route('/request', methods=['get', 'post'])
def hello():
    query = request.args
    post = request.form
    return f"query:{query}"\
           f"post:{post}"


@app.route('/session')
def session_handle():
    for k, v in request.args.items():
        session[k] = v
    resp = make_response({k: v for k, v in session.items()})
    for k, v in request.args.items():
        resp.set_cookie(f"cookie_{k}", v)
    return resp


if __name__ == '__main__':
    # 使用run方法启动后端服务
    app.run(port=8000, debug=True)
